//引入Vue
import Vue from "vue";
//引入Vue-Router路由组件
import VueRouter from "vue-router";
Vue.use(VueRouter);
import AddCartSuccess from '@/pages/AddCartSuccess'
import ShopCart from '@/pages/ShopCart'

import Center from '@/pages/Center'
import OrderList from '@/pages/Center/orderList'
import OrderDetail from '@/pages/Center/orderDetail'
const routes = [
  {

    path: "/Home",
    name: "Home",
    component: () => import("@/pages/home/index.vue"),
    meta: { isShow: true }
  },

  {
    path: "/Login",
    name: "Login",
    component: () => import("@/pages/Login/login.vue"),
    meta: { isShow: false }
  },

  {
    path: "/tip",
    name: "tip",
    component: () => import("@/pages/Login/tip.vue"),
    meta: { isShow: false }

  },

  {
    path: "/search/:keyWord?",
    name: "search",
    component: () => import("@/pages/search/index.vue"),
    meta: { isShow: true }
  },
  {
    path: "/addCartSuccess",
    component: AddCartSuccess,
    name: 'addCartSuccess',
    meta: { isShow: true },
  },
  {
    path: "/shopcart/:skuNum?",
    component: ShopCart,
    name: 'shopcart',
    meta: { isShow: true },
  },
  {
    path: "/detail/:sid?",
    name: "detail",
    component: () => import("@/pages/Detail/index.vue"),
    meta: { isShow: true }
  },

  {
    path: "/Test",
    name: "Test",
    component: () => import("@/pages/Test/test.vue"),
    meta: { isShow: true }
  },

  {
    path: "/Pay",
    name: "Pay",
    component: () => import("@/pages/Pay/pay.vue"),
    meta: { isShow: true }
  },
  {
    path: '/center',
    component: Center,
    meta: { isShow: true },
    children: [
      {

        path: 'orderlist',
        component: OrderList
      },
      {
        path: 'orderdetail',
        component: OrderDetail
      },
      {
        path: '',
        redirect: 'orderlist'
      }
    ]
  },
  {
    path: "/trade",
    name: "Trade",
    component: () => import("@/pages/Trade/index.vue"),
    meta: { isShow: true }
  },

  // 重新定向，在项目跑起来的时候，访问/立马让他定向到首页

  {
    path: '*',
    redirect: 'Home'
  }]




const originalPush = VueRouter.prototype.push;
VueRouter.prototype.push = function push(location) {
  return originalPush.call(this, location).catch((err) => err);
};

const router = new VueRouter({
  routes,
});

export default router;